/**
 *  *2010-9-3 上午11:22:39  add 
 */
package com.base.myproject.server.tools;

import java.util.Comparator;

import com.base.myproject.client.jdbc.Row;

/**
 * @author Administrator 2010-9-3 javazgw@gmail.com
 */
public class DataSetComparators implements Comparator {

	String[] leftcolumn ;
	String[] rightcolumn;
	public DataSetComparators(String[] leftcolumn ,String[] rightcolumn)
	{
		this.leftcolumn = leftcolumn;
		this.rightcolumn = rightcolumn;
	}
	public int compare(Row leftrow,Row roghtrow)
	{
		
		for(int i=0;i<this.leftcolumn.length;i++)
		{
			if(leftrow.getValue(this.leftcolumn[i]).compareTo(roghtrow.getValue(this.rightcolumn[i]))>=1)
				return 1;
			else if(leftrow.getValue(this.leftcolumn[i]).compareTo(roghtrow.getValue(this.rightcolumn[i]))<=-1)
				return -1;
		}
		return 0;
	}
	@Override
	public int compare(Object o1, Object o2) {

		return 0;
	}

	public int compare(String o1, String o2) {
		String s1 = (String) o1;
		String s2 = (String) o2;
		int len1 = s1.length();
		int len2 = s2.length();
		int n = Math.min(len1, len2);
		char v1[] = s1.toCharArray();
		char v2[] = s2.toCharArray();
		int pos = 0;

		while (n-- != 0) {
			char c1 = v1[pos];
			char c2 = v2[pos];
			if (c1 != c2) {
				return c1 - c2;
			}
			pos++;
		}
		return len1 - len2;
	}

	public int compare(Integer o1, Integer o2) {
		int val1 = o1.intValue();
		int val2 = o2.intValue();
		return (val1 < val2 ? -1 : (val1 == val2 ? 0 : 1));

	}

	public int compare(Boolean o1, Boolean o2) {

		return (o1.equals(o2) ? 0 : (o1.booleanValue() == true ? 1 : -1));

	}
}
